{% comment %}
<!--
  Copyright (C) 2008 ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
  - http://heavyz.blogspot.com/
  - http://buggarden.blogspot.com/

  The restaurant's comments section.
  
  Created on 2008-10-16.
  $Id: resto_comments.html 271 2008-11-10 14:43:10Z heavyzheng $
-->
{% endcomment %}

<div id="resto_comments" class="section">

  {% if error %}
    <div class="error message">
      {{ error }}
      <a href="javascript:void(0);" onclick="closeMessage('#resto_comments')">[close]</a>
    </div>
  {% endif %}
  
  <script type="text/javascript">//<![CDATA[
  function getCommentsByPage(number) {
      var data = { section : "resto_comments", page : number };
      var options = { type    : "GET",
                      url     : ".",
                      data    : data,
                      success : function(data) { $("#resto_comments").after(data).remove(); }
                    };
      $.ajax(options);
  }
  //]]></script>
  
  <div>
    {% for comment in comments.object_list %}
      <div>
        {% if comment.title %}
          <big><b>{{ comment.title }}</b></big>
        {% else %}
          <big><i>(Untitled)</i></big>
        {% endif %}
        <br/>
        <i>Rating: {{ comment.average_rating|floatformat:1 }}</i>
        <br/>
        <b>{{ comment.author.nickname }}</b>
        commented at
        {{ comment.post_date|date:"Y-m-d h:i:s A" }}:
        <br/>
        <p>{{ comment.content|escape|linebreaks }}</p>
        {% if is_admin %}
          <a href="#TODO">[delete]</a>
        {% endif %}
      </div>
    {% endfor %}
  </div>
  
  <div class="pagination">
  
    {% if comments.has_previous %}
      <span class="page">
        <a href="javascript:void(0);" onclick="getCommentsByPage({{ comments.previous_page_number }});">Prev</a>
      </span>
    {% else %}
      <span class="page">Prev</span>
    {% endif %}
    
    {% if not comments.is_first_page_in_range %}
      <span class="page">
        <a href="javascript:void(0);" onclick="getCommentsByPage({{ comments.first_page_number }});">{{ comments.first_page_number }}</a>
      </span>
    {% endif %}
    
    {% for page in comments.previous_page_range %}
      <span class="page">
        <a href="javascript:void(0);" onclick="getCommentsByPage({{ page }});">{{ page }}</a>
      </span>
    {% endfor %}
    
    <span class="page">
      <b>{{ comments.number }}</b>
    </span>
    
    {% for page in comments.next_page_range %}
      <span class="page">
        <a href="javascript:void(0);" onclick="getCommentsByPage({{ page }});">{{ page }}</a>
      </span>
    {% endfor %}
    
    {% if not comments.is_last_page_in_range %}
      <span class="page">
        <a href="javascript:void(0);" onclick="getCommentsByPage({{ comments.last_page_number }});">{{ comments.last_page_number }}</a>
      </span>
    {% endif %}
    
    {% if comments.has_next %}
      <span class="page">
        <a href="javascript:void(0);" onclick="getCommentsByPage({{ comments.next_page_number }});">Next</a>
      </span>
    {% else %}
      <span class="page">Next</span>
    {% endif %}

  </div>

</div><!--/#resto_comments-->

